<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">

<head>
	<%@ include file="header.jsp"%>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">

    <title> - 登录</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">
    <link href="css/login.css" rel="stylesheet">
    <!--[if lt IE 9]>
    <meta http-equiv="refresh" content="0;ie.html" />
    <![endif]-->
    <script>
        if (window.top !== window.self) {
            window.top.location = window.location;
        }
    </script>

</head>

<body class="signin">
    <div class="signinpanel">
        <div class="row">
            <div class="col-sm-12">
                <form id="formId" method="post" action="">
                    <h4 class="no-margins">登录：</h4>
                    <p class="m-t-md">登录到H+后台主题UI框架</p>
                    <input type="text" id="name" name="name" class="form-control uname" placeholder="用户名" />
                    <input type="password" id="password" name="password" class="form-control pword m-b" placeholder="密码" />
                    <a href="">忘记密码了？</a>
                    <input type="button" class="btn btn-success btn-block" onclick="submitForm()"  value="登录"/>
                </form>
            </div>
        </div>
        <div class="signup-footer">
            <div class="pull-left">
                &copy; hAdmin
            </div>
        </div>
    </div>
    
    <script type="text/javascript">
		function submitForm() {
			// 首先在前台使用正则表达式验证格式对不对
			var name = $('#name').val();
			var reg = /^\w{5,10}$/;
			if (reg.test(name) == false) {
				mylayer.errorMsg('您输入的用户名不是5-10字母数字下划线');
				return;
			}
			
			
			$.post(
				'${path}/user?method=login',
				$('#formId').serialize(), // 可以把form表的里面的数据自动封装成json格式
				function(jsonResult) {
					console.log(jsonResult);
					if (jsonResult.code == 0) {
						mylayer.okUrl(jsonResult.msg, '${path}/');
					} else {
						mylayer.errorMsg(jsonResult.msg);
					}
				},
				'json'
			);
		}
	</script>
</body>

</html>
